package com.demo.gateway.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

import com.demo.gateway.mapper.provider.RouteMapperProvider;
import com.demo.gateway.pojo.GatewayRouteDO;

/**
 * @author: demo
 * @date: 2020年7月3日
 * @Document : 路由操作类
 */
@Mapper
public interface RoutesMapper {

	
	/**
	 * 增加路由信息
	 * @param route
	 * @return
	 */
	@InsertProvider(type = RouteMapperProvider.class,method = "addRouteProvider")
	public int addRoute(GatewayRouteDO route);
	
	/**
	 * 删除路由信息
	 * @param id
	 * @return
	 */
	@Delete(" delete from gateway_routes where id=#{id}")
	public int deleteRoute(String id);
	
	
	/**
	 * 查询当前id的order 同时也代表数量
	 * @param id
	 * @return
	 */
	@Select(" SELECT  IFNULL(MAX(orders),0) FROM gateway_routes WHERE id=#{id}")
	public int  queryRouteOrder(String id);
	
	/**
	 * 获取当前location 的顺序
	 * @param location
	 * @return
	 */
	@Select(" SELECT  IFNULL(MAX(orders),0)  FROM gateway_routes WHERE location=#{location}")
	public  int  queryMaxRouteOrder(String  location);
	
	
	/**
	 * 更新路由信息
	 * @param route
	 * @return
	 */
	@UpdateProvider(type = RouteMapperProvider.class,method = "updateRouteProvider")
	public  int  updateRoute(GatewayRouteDO route);
}
